package cloud.xlh.my_system.controller;

import cloud.xlh.domin.dto.UserDTO;
import cloud.xlh.domin.po.UserPO;
import cloud.xlh.my_system.annotation.UserInfoParam;
import cloud.xlh.my_system.flow.UserRegisterFlow;
import cloud.xlh.my_system.service.UserService;
import cloud.xlh.my_system.tradeflow.EcnyTradeContext;
import cloud.xlh.my_system.tradeflow.TradeFlowRuner;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/1/18 22:02
 * @ Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private TradeFlowRuner tradeFlowRuner;

    @RequestMapping( "/register")
    public JSONObject register(@UserInfoParam UserDTO userDTO) {
        System.out.println(userDTO);
        UserDTO userRegisterInfoDTO = (UserDTO) tradeFlowRuner.execute(UserRegisterFlow.TRADE_FLOW, EcnyTradeContext.getInstance(userDTO));
        //log.info("用户注册成功，用户注册信息->{}" , userDTO);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("retCode" , "PR00");
        jsonObject.put("retInfo" , "SUCCESS");
        jsonObject.put("userRegisterInfo" , userDTO);
        return jsonObject;
    }

    @Resource
    private UserService userService;
    @GetMapping( "/getAllSystemUser")
    public JSONObject getAllSystemUser() {
        List<UserPO> userPOList = userService.getAllSystemUser();
        //log.info("用户注册成功，用户注册信息->{}" , userDTO);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("retCode" , "PR00");
        jsonObject.put("retInfo" , "SUCCESS");
        jsonObject.put("userRegisterInfo" , userPOList);
        return jsonObject;
    }
}
